package dpda;

import org.junit.jupiter.api.Test;
import pda.PDAConfiguration;
import pda.PDARule;
import pda.Stack;

import java.util.Arrays;
import java.util.List;

/**
 * @author haoly
 * @title DPDARulebookTest
 * @date 2025/4/21 10:55
 * @description TODO
 */
public class DPDARulebookTest {
    @Test
    public void testNextConfiguration(){
        List<PDARule<Integer>> rules = Arrays.asList(
                new PDARule<>(1, '(', 2, '$', "b$"),
                new PDARule<>(2, '(', 2, 'b', "bb"),
                new PDARule<>(2, ')', 2, 'b', ""),
                new PDARule<>(2, null, 1, '$', "$")
        );
        DPDARulebook<Integer> rulebook = new DPDARulebook<>(rules);
        System.out.println(rulebook);

        Stack<Character> stack = new Stack<>(Arrays.asList('$'));
        PDAConfiguration<Integer> configuration = new PDAConfiguration<>(1, stack);
        configuration = rulebook.nextConfiguration(configuration, '(');
        System.out.println(configuration);
        configuration = rulebook.nextConfiguration(configuration, '(');
        System.out.println(configuration);
        configuration = rulebook.nextConfiguration(configuration, ')');
        System.out.println(configuration);
    }

    @Test
    public void testFollowFreeMoves(){
        List<PDARule<Integer>> rules = Arrays.asList(
                new PDARule<>(1, '(', 2, '$', "b$"),
                new PDARule<>(2, '(', 2, 'b', "bb"),
                new PDARule<>(2, ')', 2, 'b', ""),
                new PDARule<>(2, null, 1, '$', "$")
        );
        DPDARulebook<Integer> rulebook = new DPDARulebook<>(rules);
        System.out.println(rulebook);

        Stack<Character> stack = new Stack<>(Arrays.asList('$'));
        PDAConfiguration<Integer> configuration = new PDAConfiguration<>(2, stack);
        System.out.println(configuration);
        configuration = rulebook.followFreeMoves(configuration);
        System.out.println(configuration);
    }
}
